package com.xiaoxie.controller;

import com.xiaoxie.entity.BaseContext;
import com.xiaoxie.entity.Lexicon;
import com.xiaoxie.entity.Result;
import com.xiaoxie.service.ILexiconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/lexicons")
public class lexiconController {
    @Autowired
    private ILexiconService iLexiconService;

    //获取词本
    @GetMapping
    public Result<List<Lexicon>> lexicons(){
        return new Result<>(200,"success",
                iLexiconService.findAll(BaseContext.getCurrentAccount()));
    }


    //获取左右可访问词本
    @PostMapping
    public Result<List<Lexicon>> showLexicons(){
        return new Result<>(200,"success",
                iLexiconService.showAll(BaseContext.getCurrentAccount()));
    }

    //删除词本
    @DeleteMapping("/{id}")
    public Result<String> deleteLexicon(@PathVariable Integer id){
        iLexiconService.delete(BaseContext.getCurrentAccount(),id);
        return Result.success();
    }
}
